package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyPersonnelShiftVo;
import com.ruoyi.system.bo.ZsyyPersonnelShiftQueryBo;
import com.ruoyi.system.bo.ZsyyPersonnelShiftAddBo;
import com.ruoyi.system.bo.ZsyyPersonnelShiftEditBo;
import com.ruoyi.system.service.IZsyyPersonnelShiftService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 人员管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "人员管理控制器", tags = {"人员管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/personnelShift")
public class ZsyyPersonnelShiftController extends BaseController {

    private final IZsyyPersonnelShiftService iZsyyPersonnelShiftService;

    /**
     * 查询人员管理列表
     */
    @ApiOperation("查询人员管理列表")
    @PreAuthorize("@ss.hasPermi('system:personnelShift:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyPersonnelShiftVo> list(@Validated ZsyyPersonnelShiftQueryBo bo) {
        return iZsyyPersonnelShiftService.queryPageList(bo);
    }

    /**
     * 导出人员管理列表
     */
    @ApiOperation("导出人员管理列表")
    @PreAuthorize("@ss.hasPermi('system:personnelShift:export')")
    @Log(title = "人员管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyPersonnelShiftVo> export(@Validated ZsyyPersonnelShiftQueryBo bo) {
        List<ZsyyPersonnelShiftVo> list = iZsyyPersonnelShiftService.queryList(bo);
        ExcelUtil<ZsyyPersonnelShiftVo> util = new ExcelUtil<ZsyyPersonnelShiftVo>(ZsyyPersonnelShiftVo.class);
        return util.exportExcel(list, "人员管理");
    }

    /**
     * 获取人员管理详细信息
     */
    @ApiOperation("获取人员管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:personnelShift:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyPersonnelShiftVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Integer id) {
        return AjaxResult.success(iZsyyPersonnelShiftService.queryById(id));
    }

    /**
     * 新增人员管理
     */
    @ApiOperation("新增人员管理")
    @PreAuthorize("@ss.hasPermi('system:personnelShift:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyPersonnelShiftAddBo bo) {
        return toAjax(iZsyyPersonnelShiftService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改人员管理
     */
    @ApiOperation("修改人员管理")
    @PreAuthorize("@ss.hasPermi('system:personnelShift:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyPersonnelShiftEditBo bo) {
        return toAjax(iZsyyPersonnelShiftService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除人员管理
     */
    @ApiOperation("删除人员管理")
    @PreAuthorize("@ss.hasPermi('system:personnelShift:remove')")
    @Log(title = "人员管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Integer[] ids) {
        return toAjax(iZsyyPersonnelShiftService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
